package com.android.support.lib.universal.view.gamepad;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Context;
import android.os.Vibrator;
import android.view.KeyEvent;

import com.android.support.lib.universal.R;
import com.android.support.lib.universal.base.BaseApplication;
import com.android.support.lib.universal.util.UtilSharedPreferences;
import com.android.support.lib.universal.util.UtilSoundPool;

/**
 * 手柄按键值
 */
@SuppressLint("InlinedApi")
public class GamepadConfig {
    public final static int KEY_CODE_A = KeyEvent.KEYCODE_BUTTON_A;
    public final static int KEY_CODE_B = KeyEvent.KEYCODE_BUTTON_B;
    public final static int KEY_CODE_X = KeyEvent.KEYCODE_BUTTON_X;
    public final static int KEY_CODE_Y = KeyEvent.KEYCODE_BUTTON_Y;
    public final static int KEY_CODE_L = KeyEvent.KEYCODE_BUTTON_L1;

    public final static int KEY_CODE_UP = KeyEvent.KEYCODE_DPAD_UP;
    public final static int KEY_CODE_DOWN = KeyEvent.KEYCODE_DPAD_DOWN;
    public final static int KEY_CODE_LEFT = KeyEvent.KEYCODE_DPAD_LEFT;
    public final static int KEY_CODE_RIGHT = KeyEvent.KEYCODE_DPAD_RIGHT;
    public final static int KEY_CODE_SELECT = KeyEvent.KEYCODE_BUTTON_SELECT;
    public final static int KEY_CODE_START = KeyEvent.KEYCODE_BUTTON_START;
    public final static int KEY_CODE_EXIT = KeyEvent.KEYCODE_BACK;

    public static UtilSharedPreferences utilSharedPreferences = UtilSharedPreferences
            .getSharedPreferencesUtil("gamepad");
    public static UtilSoundPool pool = new UtilSoundPool();

    //按键震动时长
    public final static long VIBRATE_TIME = 100;
    //初始化按键声音
    public static void INITSOUND() {
        if (pool != null) {
            int[] bea = new int[]{R.raw.lib_bea};
            pool.load(BaseApplication.getInstance(), bea, null);
        }
    }
    //震动
    public static void Vibrate() {
        Vibrator vib = (Vibrator) BaseApplication.getInstance()
                .getSystemService(Service.VIBRATOR_SERVICE);
        vib.vibrate(VIBRATE_TIME);
    }
    // 是否开启震动
    public static String SBVIBRATE = "BVIBRATE";
    public static Boolean BVIBRATE = utilSharedPreferences.getBoolean(SBVIBRATE, true);
    //是否开启音效
    public static String SBSOUND = "BSOUND";
    public static Boolean BSOUND = utilSharedPreferences.getBoolean(SBSOUND, false);
    //音效，震动。
    public static void STYLE() {
        if (BVIBRATE) {
            Vibrate();
        }
        if (BSOUND) {
            pool.play(0, 1);
        }

    }
}
